<?php
class M_document extends CI_Model {
	
	function getlist($limit,$offset,$filter){
		$this->db->limit($limit);
		$this->db->offset($offset);
		$this->db->select('dokumen_id,dokumen_nama,dokumen_isi');
		$this->db->where('dokumen_aktif','Y');
		if(!empty($filter)){
			$this->db->where("lower(`dokumen_nama`)  like '%".addslashes(strtolower($filter))."%'"); 
		}
		$query = $this->db->get('m_dokumen');
		$total = $query->num_rows();
		$arr = array();
		foreach ($query->result() as $q){
			$arr[] = $q;
		}
		$final = array('results' => $arr,'total' => $total);
		return json_encode($final);
	}
	function insert($data){
		$this->db->insert('m_dokumen',$data);
	}
	function edit($data,$dokumen_id){
		$this->db->where('dokumen_id',$dokumen_id);
		$this->db->update('m_dokumen',$data);
	}	
	
	function delete($data,$dokumen_id){
		$this->db->where('dokumen_id',$dokumen_id);
		$this->db->update('m_dokumen',$data);
	}
	
}